package com.cscp.javastudy.basic.reflect;

public class ClassLoaderDemo {

    public static void main(String[] args) throws ClassNotFoundException {
        // 获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);
        // 获取系统类加载器的父类加载器 -> 扩展类加载器
        ClassLoader parent = systemClassLoader.getParent();
        System.out.println(parent);
        // 获取根类加载器 (c++编写的，无法被获取)
        ClassLoader parent1 = parent.getParent();
        System.out.println(parent1);// null

        // 测试当前类是哪个类加载器加载的
        ClassLoader classLoader = Class.forName("com.cscp.javastudy.basic.reflect.ClassLoaderDemo").getClassLoader();
        System.out.println(classLoader);
        // 测试JDK内部类的加载器
        ClassLoader classLoader2 = Class.forName("java.lang.Object").getClassLoader();
        System.out.println(classLoader2); //null

        //如何获取系统类加载可以加载的路径
        System.out.println(System.getProperty("java.class.path"));
        /*
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\charsets.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\deploy.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\access-bridge-64.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\cldrdata.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\dnsns.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jaccess.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\jfxrt.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\localedata.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\nashorn.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunec.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunjce_provider.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunmscapi.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\sunpkcs11.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\ext\zipfs.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\javaws.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\jce.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfr.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\jfxswt.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\jsse.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\management-agent.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\plugin.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\resources.jar;
          C:\Program Files\Java\jdk1.8.0_211\jre\lib\rt.jar;
          D:\Users\46070\IdeaProjects\cscp\java-study\target\classes;
          D:\Users\46070\.m2\repository\org\springframework\boot\spring-boot-starter\2.6.7\spring-boot-starter-2.6.7.jar;
          D:\Users\46070\.m2\repository\org\springframework\boot\spring-boot\2.6.7\spring-boot-2.6.7.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-context\5.3.19\spring-context-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-aop\5.3.19\spring-aop-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-beans\5.3.19\spring-beans-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-expression\5.3.19\spring-expression-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\springframework\boot\spring-boot-autoconfigure\2.6.7\spring-boot-autoconfigure-2.6.7.jar;
          D:\Users\46070\.m2\repository\org\springframework\boot\spring-boot-starter-logging\2.6.7\spring-boot-starter-logging-2.6.7.jar;
          D:\Users\46070\.m2\repository\ch\qos\logback\logback-classic\1.2.11\logback-classic-1.2.11.jar;
          D:\Users\46070\.m2\repository\ch\qos\logback\logback-core\1.2.11\logback-core-1.2.11.jar;
          D:\Users\46070\.m2\repository\org\apache\logging\log4j\log4j-to-slf4j\2.17.2\log4j-to-slf4j-2.17.2.jar;
          D:\Users\46070\.m2\repository\org\apache\logging\log4j\log4j-api\2.17.2\log4j-api-2.17.2.jar;
          D:\Users\46070\.m2\repository\org\slf4j\jul-to-slf4j\1.7.36\jul-to-slf4j-1.7.36.jar;
          D:\Users\46070\.m2\repository\jakarta\annotation\jakarta.annotation-api\1.3.5\jakarta.annotation-api-1.3.5.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-core\5.3.19\spring-core-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\springframework\spring-jcl\5.3.19\spring-jcl-5.3.19.jar;
          D:\Users\46070\.m2\repository\org\yaml\snakeyaml\1.29\snakeyaml-1.29.jar;
          D:\Users\46070\.m2\repository\org\slf4j\slf4j-api\1.7.36\slf4j-api-1.7.36.jar;
          D:\devinstall\IntelliJ IDEA 2020.2\lib\idea_rt.jar
         */

    }
}
